package com.design.working.vo;

/**
 * 后端返回的接口
 *
 * @author gavin
 * @date 2022/5/1 11:29
 */
public class ResponseVO<T> {
    private Integer code;
    private String msg;
    private Integer count;
    private T data;

    public ResponseVO() {
    }

    public ResponseVO(Integer status, String msg, Integer count, T data) {
        this.code = status;
        this.msg = msg;
        this.count = count;
        this.data = data;
    }

    public ResponseVO(Integer status, T data) {
        this.code = status;
        this.data = data;
    }

    public ResponseVO(Integer status, String msg) {
        this.code = status;
        this.msg = msg;
    }


    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getStatus() {
        return code;
    }

    public void setStatus(Integer status) {
        this.code = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 适用于返回单条数据
     */
    public static <T> ResponseVO<T> success(T data) {
        return new ResponseVO<T>(0, "", 1, data);
    }

    /**
     * 适用于返回需要分页的数据
     */
    public static <T> ResponseVO<T> success(int count, T data) {
        return new ResponseVO<T>(0, "", count, data);
    }

    /**
     * 适用于返回错误信息
     */
    public static <T> ResponseVO<T> error(String msg) {
        return new ResponseVO<T>(-1, msg);
    }

    @Override
    public String toString() {
        return "ResponseVO{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", count=" + count +
                ", data=" + data +
                '}';
    }
}
